Skip to content

fix(mqtt): fixed how mqtt library is imported #514

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jan 27, 2023

Conversation

csarnataro
Copy link
Contributor

Because of some issues with some bundlers (namely, Parcel 2) we have updated the way mqtt.connect is imported in Connection.ts

Minor updates to index.ts (eslint)

Added a changelog section in readme file

Because of some issues with some bundlers (namely, Parcel 2)
we have updated the way mqtt.connect is imported in Connection.ts

Minor updates to index.ts (eslint)

Added a changelog section in readme file
@csarnataro csarnataro requested a review from pirropirro January 16, 2023 15:51
@CLAassistant
Copy link

CLAassistant commented Jan 16, 2023

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Regenerated package-lock.json
Updated TokenConnectionBuilder constructor to use the right mqtt.connect
function
@@ -106,7 +111,8 @@ export class Connection implements IConnection {
else valueToSend = value;
});

if (valueToSend !== {}) messages.push({ topic, propertyName: current, value: valueToSend });
// the condition `if (valueToSend !== {}) ` has been removed bc it always evaluates to true

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: maybe here is worth understanding if is better to remove the if or leaving the if fixing the condition

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, it makes sense, I'm going to see if I can understand the original intention

Added a check before sending MQTT empty objects.
if (valueToSend !== {}) messages.push({ topic, propertyName: current, value: valueToSend });
// If the message is an object, and it's empty, it makes no sense to send it
// All other messages (e.g. non-empty objects or primitives) must be sent
if (!(typeof valueToSend === 'object' && Object.keys(valueToSend).length == 0)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fabioimpe do you think it's ok now, with an explicit check on the object and its length?
I think now is more explicit that:

  • if it's an empty object, skip sending the message
  • if it's a non-empty object, or any other value (primitive) then send it.

I thing it's rather an edge-case, which probably happens if the properties array is empty (so forEach statement is never executed) or value at line 111 is an empty object.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I think now is cleaner.
Maybe you can think about extracting the condition to be more readable, but this seems the right way 👍

@csarnataro csarnataro merged commit 96ef8cc into master Jan 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants